package com.cx.service;

import com.cx.support.SpringContextHolder;
import org.springframework.data.redis.core.*;

/**
 * Created on 2019-04-18 15:42.
 * @author Alan Shu
 */
//@Component
public class CacheStringTemplate {

    private static RedisTemplate<String, String> template;
    private static ValueOperations<String, String> valueOperations;
    private static ListOperations<String, String> listOperations;
    private static SetOperations<String, String> setOperations;
    private static HashOperations<String, Object, String> hashOperations;
    private static ZSetOperations<String, String> zsetOperations;

    public static void init(SpringContextHolder springContext) {
        template = springContext.getBean("stringRedisTemplate", RedisTemplate.class);
        initOperations();
    }

    public static RedisTemplate<String, String> getRedisTemplate() {
        return template;
    }

    public static ValueOperations<String, String> valueOperations() {
        return valueOperations;
    }

    public static ListOperations<String, String> listOperations() {
        return listOperations;
    }

    public static SetOperations<String, String> setOperations() {
        return setOperations;
    }

    public static HashOperations<String, Object, String> hashOperations() {
        return hashOperations;
    }

    public static ZSetOperations<String, String> zsetOperations() {
        return zsetOperations;
    }

    public static void initOperations() {
        valueOperations = template.opsForValue();
        listOperations = template.opsForList();
        setOperations = template.opsForSet();
        hashOperations = template.opsForHash();
        zsetOperations = template.opsForZSet();
    }
}